import { modal } from 'vue-strap'
import { swapAd, showMsg, updateState } from '../../../vuex/action'

export default {
  name: 'GaoNew',
  components: {
    'vue-modal': modal
  },
  data() {
    return {
      modalStatus: false,
      fromId: '',
      toId: ''
    }
  },
  vuex: {
    actions: {
      xSwapAd: swapAd,
      xShowMsg: showMsg,
      xUpdateState: updateState
    }
  },
  methods: {
    showModal() {
      this.modalStatus = true
    },
    submit() {
      this.xSwapAd({
        fromId: +this.fromId,
        toId: +this.toId
      })
        .then(() => {
          this.modalStatus = false
          this.fromId = ''
          this.toId = ''
          this.xUpdateState('GAO_LIST_NEED_FRESH', 1)
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    }
  }
}
